#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

#include "bounded_vector.h"

namespace UnitTestUppg4
{		
	TEST_CLASS(UnitTest1)
	{
	public:

		TEST_METHOD(TestEmpty)
		{
			bounded_vector bv;
			Assert::AreEqual(true, bv.isEmpty());
		}

		TEST_METHOD(TestConstructorAndSize)
		{
			bounded_vector bv('a', 'z');
			Assert::AreEqual(true, bv.getSize() == 26);
			bounded_vector bv2('a', 'e');
			Assert::AreEqual(true, bv2.getSize() == 5);
		}

		TEST_METHOD(TestIndexOperator)
		{
			bounded_vector bv('a', 'z');
			Assert::AreEqual(true, bv['k'] == 0);
			bv['k']++;
			Assert::AreEqual(true, bv['k'] == 1);
			int n = bv['k'];
			bv['e'] = 10;
			Assert::AreEqual(true, bv['e'] == 10);
		}

		TEST_METHOD(TestOperatorEquals)
		{
			bounded_vector bv('a', 'z');
			bounded_vector bv2('a', 'z');
			bounded_vector bv3('a', 'x');
			bv['b'] = 10;
			bv2['b'] = 10;
			bv3['b'] = 10;
			Assert::AreEqual(true, bv == bv2);
			Assert::AreEqual(false, bv == bv3);
		}

		TEST_METHOD(TestCopyConstr)
		{
			bounded_vector bv('a', 'z');
			bv['z'] = 100;
			bounded_vector bv2(bv);
			Assert::AreEqual(true, bv2['z'] == 100);
		}

		TEST_METHOD(TestCopyAssign)
		{
			bounded_vector bv('a', 'z');
			bounded_vector bv2('a', 'b');
			bv['e'] = 20;
			bv2 = bv;
			Assert::AreEqual(true, bv2['e'] == 20);
		}

		TEST_METHOD(TestSum)
		{
			bounded_vector bv('a', 'z');
			bv['k']++;
			bv['e'] = 10;
			bv['z'] = 100;
			bv['e'] += 20;
			bv['b'] = 10;
			Assert::AreEqual(true, bv.sum() == 141);
		}

		TEST_METHOD(TestAddVectors)
		{
			bounded_vector bv('a', 'z');
			bounded_vector bv2('a', 'e');
			bv['e'] = 20;
			bv2['e'] = 10;
			bv2['b'] = 10;
			bounded_vector bv3 = bv + bv2;
			Assert::AreEqual(true, bv3['e'] == 30);
			Assert::AreEqual(true, bv3['b'] == 10);
			Assert::AreEqual(true, bv3.sum() == 40);
		}

		TEST_METHOD(TestIterator)
		{
			bounded_vector bv('a', 'z');
			bv['k']++;
			bv['e'] = 10;
			bv['z'] = 100;
			bv['e'] += 20;
			bv['b'] = 10;
			int sum = 0;
			for (auto it = bv.begin(); it != bv.end(); it++)
			{
				sum += *it;
			}
			Assert::AreEqual(true, bv.sum() == sum);
		}
	};
}